if ("serviceWorker" in navigator) {
  window.addEventListener("load", function(){
    navigator.serviceWorker.register("/sw.js", {scope: '/'}).then(function(reg){
      console.log("ServiceWorker注册成功");
      console.log(reg);
      
    }).catch(function(err){
      console.log("注册失败");
      console.log(err);
    })
  });
}

window.addEventListener('beforeinstallprompt', function (e) {
    // beforeinstallprompt event fired

    e.userChoice.then(function (choiceResult) {
        if (choiceResult.outcome === 'dismissed') {
            console.log('用户取消安装应用');
        }
        else {
            console.log('用户安装了应用');
        }
    });
});